package medium全排列;

import org.testng.annotations.Test;

import java.util.ArrayList;
import java.util.List;

public class Solution {
    public List<List<Integer>> permute(int[] nums) {
        List<List<Integer>> list = new ArrayList<>();
        List<Integer> list1 = new ArrayList<>();
        mute(list,list1,nums);
        System.out.println(list.toString());
        return list;
    }
    public void mute(List<List<Integer>> list, List<Integer> list1, int[] nums){
        if (list1.size() == nums.length ) {
            list.add(new ArrayList<>(list1));
            return;
        }
        for (int k = 0; k < nums.length; k++) {
            if (!list1.contains(nums[k])){
                list1.add(nums[k]);
                mute(list,list1,nums);
                list1.remove(list1.size() - 1);
            }
        }
    }
    @Test
    public void test(){
        int[] nums = {1,2,3};
        List<List<Integer>> list = permute(nums);
        for (List<Integer> list1:
                list) {
            System.out.println(list1.toString());
        }
    }
}
